from glumpy import app, gloo, gl, ext
from wisp.framework import WispState


scene_state = WispState()   # Joint trainer / app state
wisp_state = scene_state
gl_version=wisp_state.renderer.gl_version
# Currently assume glfw backend due to integration with imgui
print(gl_version)

app.use(f"glfw_imgui ({gl_version})")
# app.use("glfw ({gl_version})")
win_config = app.configuration.Configuration()
# win_config = app.configuration.get_default()
# win_config.major_version = 3
# win_config.minor_version = 3
# win_config.profile = "core"

print(win_config)
if wisp_state.renderer.antialiasing == 'msaa_4x':
    win_config.samples = 4

width = wisp_state.renderer.canvas_width
height = wisp_state.renderer.canvas_height
window = app.Window(width=width, height=height, title="wisp app", config=win_config)


handle = gl.glGenTextures(1)
target = gl.GL_TEXTURE_2D
gl.glBindTexture(target, handle)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_REPEAT)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_REPEAT)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR_MIPMAP_LINEAR)
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
try:
    gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAX_ANISOTROPY, 16)
except AttributeError as e:
    print('GL_TEXTURE_MAX_ANISOTROPY not available; appearance may suffer')
gl.glGenerateMipmap(gl.GL_TEXTURE_2D)